package com.feicheng.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Astore;
import com.feicheng.service.a.FJlService;
import com.feicheng.service.a.FMdService;
import com.feicheng.service.a.FXyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/store")
public class MdController {

    @Autowired
    FMdService mdService;
    @Autowired
    FJlService jlService;
    @Autowired
    FXyService xyService;

    @GetMapping("/page")
    public ResultInfo getByPage(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "12") Integer size,
            String searchKey
    ) {
        JSONObject param = new JSONObject();
        param.put("current", current);
        param.put("size", size);
        param.put("sname", searchKey);
        param = mdService.getMdByPage(param);
        return ResultInfo.success(param.get("astores"));
    }

    @PutMapping("/info")
    public ResultInfo updateInfo(@RequestBody Astore astore) {
        JSONObject param = new JSONObject();
        param.put("astore", astore);
        param = mdService.updateMd(param);
        return ResultInfo.success(param.get("astore"));
    }

    @PostMapping("/new")
    public ResultInfo newInfo(@RequestBody Astore astore) {
        JSONObject param = new JSONObject();
        param.put("astore", astore);
        param = mdService.newMd(param);
        return ResultInfo.success(param.get("astore"));
    }

    @GetMapping("/info")
    public ResultInfo getInfo(String storeid) {
        JSONObject param = new JSONObject();
        param.put("storeid", storeid);
        param = mdService.getMd(param);
        return ResultInfo.success(param);
    }

    @GetMapping("/amont")
    public ResultInfo getAmont(){
        JSONObject param = mdService.getMdsWithAmont();
        return ResultInfo.success(param);
    }

    @PostMapping("/import")
    public ResultInfo importMd(@RequestBody JSONObject param) {
        return ResultInfo.success(mdService.importMd(param));
    }
}
